<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 09/01/2019
 * Time: 11:18
 */

namespace App\Modules\UCenter;


use App\Services\Message\MessageIndex;

class Message extends BaseUcenter
{
    /*一对一发送站内信*/
    public function sendOneMessage(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = $this->postData;
        $data['from_uid'] = $res['res']['id'];
        $data['type'] = 1;
        return MessageIndex::Message()->sendOneMessage($data);
    }
    /*回复某个站内信*/
    public function replyOneMessage(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = pick_array($this->postData, ['id','user_id','content','orther_info']);
        return MessageIndex::Message()->replyOneMessage($data);
    }
    /*用户删除某个站内信*/
    public function delOneMessage(): array
    {
        $res = $this->isLogin();
        if ($res['status'] !== SUCCESS_STATUS) {
            return need_login($res,'请登录');
        }
        $data = pick_array($this->postData, ['id']);
        $data['user_id'] = $res['res']['id'];
        return MessageIndex::Message()->delOneMessage($data);
    }
    /*查看某用户的收件箱、发件箱*/
    public function messageList(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return MessageIndex::Message()->messageList($data);
    }

    /*管理员查看站内信列表*/
    public function adminMessageList(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return MessageIndex::Message()->adminMessageList($data);
    }

    /*管理员删除站内信*/
    public function adminDelOneMessage(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return MessageIndex::Message()->adminDelOneMessage($data);
    }

    /*某个站内信详情*/
    public function messageInfo(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return MessageIndex::Message()->messageInfo($data);
    }
    /*站内信标记已读*/
    public function markRead(): array
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return MessageIndex::Message()->markRead($data);
    }
}
